<?php
//
// +---------------------------------------------------------------------------------+
// | Package: EezeeSite Core                                                         |
// +---------------------------------------------------------------------------------+
// | Copyright (C) 2006  EezeeSite Development Team                                  |
// +---------------------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or                   |
// | modify it under the terms of the GNU General Public License                     |
// | as published by the Free Software Foundation; either version 2                  |
// | of the License, or (at your option) any later version.                          |
// |                                                                                 |
// | This program is distributed in the hope that it will be useful,                 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                  |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                   |
// | GNU General Public License for more details.                                    |
// |                                                                                 |
// | You should have received a copy of the GNU General Public License               |
// | along with this program; if not, write to the Free Software                     |
// | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. |
// +---------------------------------------------------------------------------------+
// | Author: Mayukh De <mayukhde@gmail.com>                                          |
// +---------------------------------------------------------------------------------+
//

class ESDBOps extends DB_Table
{
    var $fetchmode = DB_FETCHMODE_ASSOC;

    function resetVars($tableName)
    {
        global $DBSchemaConfigs;
        $this->col = $DBSchemaConfigs['PROPERTIES'][$tableName];
        $this->idx = $DBSchemaConfigs['INDEX'][$tableName];
        return;
    }

    function nextID($col)
    {
        $this->sql['maxid'] = array(
                                   'select' => 'max('.$col.')'
                                   );
        $maxID = $this->select('maxid');
        $nextID = $maxID[0]['max('.$col.')'] + 1;
        return $nextID;
    }

    function createDBTables()
    {
        global $DBSchemaConfigs;
        $countTables = count($DBSchemaConfigs['TABLES']);
        $msg = '';
        for ($i = 0; $i < $countTables; $i++) {
            $this->table = $DBSchemaConfigs['TABLES'][$i];
            $this->resetVars($this->table);
            $res[$i] = $this->create('safe');
            if ($res[$i] != 1) {
                $msg.= "\n - ".$this->table;
            }
        }
        if ($msg != '') {
            $message = "This installation process was not able to create the following tables:";
            $message.= $msg;
            $message.= "\nPlease attempt to create these tables manually.";
        } else {
            $message = 'All the tables have been created successfully in the database.';
        }
        return $message;
    }    
}

?>